﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI.WebControls;

namespace Cormant.Mvc.Web
{
    [HtmlTag("table")]
    public class MvcTable : MvcControl
    {
        #region MvcTable : Constructors.
        public MvcTable(HtmlHelper html, string id)
            : base(html, id)
        {
            this.Rows = new List<MvcTableRow>();
        }
        #endregion

        #region MvcTable : Properties.
        [HtmlAttribute("cellpadding")]
        public int CellPadding { get; set; }

        [HtmlAttribute("cellspacing")]
        public int CellSpacing { get; set; }

        public IList<MvcTableRow> Rows { get; set; }

        [HtmlAttribute("width")]
        public Unit Width { get; set; }
        #endregion

        #region MvcTable : Methods.
        public override string ToString()
        {
            StringBuilder markup = new StringBuilder();
            markup.AppendLine(base.ToString(TagRenderMode.StartTag));
            if (this.Rows != null && this.Rows.Count > 0)
            {
                foreach (MvcTableRow row in this.Rows)
                {
                    if (row != null)
                        markup.AppendLine(row.ToString());
                }
            }
            markup.AppendLine(base.ToString(TagRenderMode.EndTag));
            return markup.ToString();
        }
        #endregion
    }
}
